import { defaultFormData } from '.'

export function useFormModal(modalRef: any) {
  const modalTitle = ref('')
  const formData = ref<any>({
    ...defaultFormData,
  })

  const showEditModel = async (row: any) => {
    modalTitle.value = '编辑指标'
    modalRef.value?.open?.()
    formData.value = {
      ...row,
      indicatorMultiple: row.indicatorMultiple || 1,
    }
  }

  const showAddModel = async (pointId: number = 0) => {
    modalRef.value?.open?.()
    modalTitle.value = '新增指标'
    formData.value = {
      ...defaultFormData,
      pointId,
    }
  }

  return {
    formData,
    modalTitle,

    /** 点击新增指标 */
    showAddModel,

    /** 点击编辑指标数据一行 */
    showEditModel,
  }
}
